import Vue from "vue";
import Router from "vue-router";
import store from "@/store/index";
import cookie from "js-cookie";

const Hello = () => import("@/components/Hello");
// 借款管理
// 借款申请
const Apply = () => import("@/pages/loan/apply");
// U车贷借款申请表
const ApplyTable = () => import("@/pages/loan/applyTable");
// U车贷借款申请资料上传
const ApplyDataUpload = () => import("@/pages/loan/applyDataUpload");
// U车贷借款短信验证
const ApplyMessagesCode = () => import("@/pages/loan/applyMessagesCode");
// U车贷借款存管开户
const ApplyOpenAccount = () => import("@/pages/loan/applyOpenAccount");
// 面签列表
const Interview = () => import("@/pages/loan/interview");
// 风控列表
const RiskAuditList = () => import("@/pages/loan/riskAuditList");
// 风控批复
const RiskAuditReply = () => import("@/pages/loan/riskAuditReply");
// 面签批复
const InterviewReply = () => import("@/pages/loan/interviewReply");
// 家访列表
const Visit = () => import("@/pages/loan/visit");
// 家访确认
const VisitConfirm = () => import("@/pages/loan/visitConfirm");
// 财务审核
const FinancialAudit = () => import("@/pages/loan/financialAudit");
// 风控审核
const RiskAudit = () => import("@/pages/loan/riskAudit");
// 协议上传
const Agreement = () => import("@/pages/loan/agreement");
// 合同库
const ContractLibrary = () => import("@/pages/loan/contractLibrary");
// 资产管理
const AssetsConfirm= () => import("@/pages/loan/assetsConfirm");
// 资产管理
const Assets = () => import("@/pages/loan/assets");
// 借款人详情
const BorrowerDetails = () => import("@/pages/loan/borrowerDetails");

// 发布的标1
const AssetsMarkOne = () => import("@/pages/loan/assetsMarkOne");
// 发布的标2
const AssetsMarkTwo = () => import("@/pages/loan/assetsMarkTwo");
// 发布的标3
const AssetsMarkThree = () => import("@/pages/loan/assetsMarkThree");
// 会员管理
// 会员列表
const MemberList = () => import("@/pages/member/memberList");
// 会员详情
const MemberDetail= () => import("@/pages/member/memberDetail");

// 标的管理
// 发标列表
const SubjuctList = () => import("@/pages/subject/subjectList");

// 角色管理
// 角色列表
const RoleList = () => import("@/pages/role/roleList");
// 权限配置
const Authority = () => import("@/pages/role/authority");
// 业务员
const Salesman = () => import("@/pages/role/salesman");
// 风控人员
const RiskControl = () => import("@/pages/role/riskControl");
// 财务人员
const FinancialStaff = () => import("@/pages/role/financialStaff");
// 客服人员
const SupportStaff = () => import("@/pages/role/supportStaff");
// 权限分配
const ToAllocate = () => import("@/pages/role/toAllocate");
// 权限管理
const RightsManagement = () => import("@/pages/role/rightsManagement");

// 资产管理人员
const AssetManager = () => import("@/pages/role/assetManager");
// 资产管理人员
const AssetAuditors = () => import("@/pages/role/assetAuditors");

// 用户管理
// 平台用户
const PlatformUserLoginIn = () => import("@/pages/userManagement/platformUser");
// 登陆日志
const LoginRecord = () => import("@/pages/userManagement/loginRecord");

// 登陆页
const LoginIn = () => import("@/pages/user/loginIn");
// 忘记密码
const ForgetPassword = () => import("@/pages/user/forgetPassword");
// 修改密码
const RevisePassword = () => import("@/pages/user/revisePassword");

const SuccessTips = () => import("@/pages/successTips");

const Admin = () => import("@/pages/admin");
Vue.use(Router);

const router = new Router({
    routes: [
        {
            path: "/login",
            name: "login",
            component: LoginIn
        },
        {
            path: "/revisePassword",
            component: RevisePassword,
            name: "RevisePassword"
        },
        {
            path: "/forgetPassword",
            component: ForgetPassword,
            name: "ForgetPassword"
        },
        {
            path: "/",
            component: Admin,
            name: "admin",
            redirect: "/index",
            meta: {
                // 添加该字段，表示进入这个路由是需要登录的
                requireAuth: true,
                breadcrumbName: "首页"
            },
            children: [
                {
                    path: "/index",
                    name: "hello",
                    component: Hello
                },
                {
                    path: "/apply",
                    name: "apply",
                    component: Apply,
                    meta: {
                        breadcrumbName: "借款申请列表"
                    }
                },
                {
                    path: "/applyTable",
                    name: "applyTable",
                    component: ApplyTable,
                    meta: {
                        breadcrumbName: "U车贷借款申请表"
                    }
                },
                {
                    path: "/applyDataUpload",
                    name: "applyDataUpload",
                    component: ApplyDataUpload,
                    meta: {
                        breadcrumbName: "U车贷借款申请资料上传"
                    }
                },
                {
                    path: "/applyMessagesCode",
                    name: "applyMessagesCode",
                    component: ApplyMessagesCode,
                    meta: {
                        breadcrumbName: "U车贷借款短信验证"
                    }
                },
                {
                    path: "/applyOpenAccount",
                    name: "applyOpenAccount",
                    component: ApplyOpenAccount,
                    meta: {
                        breadcrumbName: "U车贷借款存管开户"
                    }
                },
                {
                    path: "/interview",
                    name: "interview",
                    meta: {
                        // 添加该字段，表示进入这个路由是需要登录的
                        breadcrumbName: "面签列表"
                    },
                    component: Interview
                },
                {
                    path: "/riskAuditList",
                    name: "riskAuditList",
                    meta: {
                        // 添加该字段，表示进入这个路由是需要登录的
                        breadcrumbName: "风控列表"
                    },
                    component: RiskAuditList
                },
                {
                    path: "/riskAuditReply",
                    name: "riskAuditReply",
                    meta: {
                        // 添加该字段，表示进入这个路由是需要登录的
                        breadcrumbName: "风控批复"
                    },
                    component: RiskAuditReply
                },
                {
                    path: "/interview/InterviewReply",
                    name: "interviewReply",
                    component: InterviewReply,
                    meta: {
                        breadcrumbName: "面签批复"
                    }
                },
                {
                    path: "/visit",
                    name: "visit",
                    component: Visit,
                    meta: {
                        breadcrumbName: "家访列表"
                    }
                },
                {
                    path: "/visitConfirm",
                    name: "visitConfirm",
                    component: VisitConfirm,
                    meta: {
                        breadcrumbName: "家访确认"
                    }
                },
                {
                    path: "/financialAudit",
                    name: "financialAudit",
                    component: FinancialAudit,
                    meta: {
                        breadcrumbName: "财务审核"
                    }
                },
                {
                    path: "/riskAudit",
                    name: "riskAudit",
                    component: RiskAudit,
                    meta: {
                        breadcrumbName: "风控审核"
                    }
                },
                {
                    path: "/agreement",
                    name: "agreement",
                    component: Agreement,
                    meta: {
                        breadcrumbName: "协议上传"
                    }
                },
                {
                    path: "/contractLibrary",
                    name: "ContractLibrary",
                    component: ContractLibrary,
                    meta: {
                        breadcrumbName: "合同库"
                    }
                },
                {
                    path: "/assetsConfirm",
                    name: "assetsConfirm",
                    component: AssetsConfirm,
                    meta: {
                        breadcrumbName: "资产确认"
                    }
                },
                {
                    path: "/asset",
                    name: "asset",
                    component: Assets,
                    meta: {
                        breadcrumbName: "资产管理"
                    }
                },
                {
                    path: "/apply/borrowerDetails",
                    name: "borrowerDetails",
                    component: BorrowerDetails,
                    meta: {
                        breadcrumbName: "借款人详情"
                    }
                },
                {
                    path: "/memberList",
                    name: "memberList",
                    component: MemberList,
                    meta: {
                        breadcrumbName: "会员列表"
                    }
                },
                {
                    path: "/memberDetail",
                    name: "memberDetail",
                    component: MemberDetail,
                    meta: {
                        breadcrumbName: "会员详情"
                    }
                },
                {
                    path: "/subjuctList",
                    name: "subjuctList",
                    component: SubjuctList,
                    meta: {
                        breadcrumbName: "发标列表"
                    }
                },
                {
                    path: "/asset/assetsMarkOne",
                    name: "assetsMarkOne",
                    component: AssetsMarkOne,
                    meta: {
                        breadcrumbName: "发布标1"
                    }
                },
                {
                    path: "/asset/AssetsMarkTwo",
                    name: "assetsMarkTwo",
                    component: AssetsMarkTwo,
                    meta: {
                        breadcrumbName: "发布标2"
                    }
                },
                {
                    path: "/asset/AssetsMarkThree",
                    name: "assetsMarkThree",
                    component: AssetsMarkThree,
                    meta: {
                        breadcrumbName: "发布标3"
                    }
                },
                {
                    path: "/roleList",
                    name: "roleList",
                    component: RoleList,
                    meta: {
                        breadcrumbName: "角色列表"
                    }
                },
                {
                    path: "/authority",
                    name: "authority",
                    component: Authority,
                    meta: {
                        breadcrumbName: "权限配置"
                    }
                },
                {
                    path: "/toAllocate",
                    name: "toAllocate",
                    component: ToAllocate,
                    meta: {
                        breadcrumbName: "权限列表"
                    }
                },
                {
                    path: "/authority/rightsManagement",
                    name: "rightsManagement",
                    component: RightsManagement,
                    meta: {
                        breadcrumbName: "权限分配"
                    }
                },
                {
                    path: "/authority/salesman",
                    name: "salesman",
                    component: Salesman,
                    meta: {
                        breadcrumbName: "业务人员"
                    }
                },
                {
                    path: "/authority/riskControl",
                    name: "riskControl",
                    component: RiskControl,
                    meta: {
                        breadcrumbName: "风控人员"
                    }
                },
                {
                    path: "/authority/financialStaff",
                    name: "financialStaff",
                    component: FinancialStaff,
                    meta: {
                        breadcrumbName: "账务人员"
                    }
                },
                {
                    path: "/authority/supportStaff",
                    name: "supportStaff",
                    component: SupportStaff,
                    meta: {
                        breadcrumbName: "客服人员"
                    }
                },
                {
                    path: "/authority/assetAuditors",
                    name: "assetAuditors",
                    component: AssetAuditors,
                    meta: {
                        breadcrumbName: "客服人员"
                    }
                },
                {
                    path: "/platformUser",
                    name: "platformUser",
                    component: PlatformUserLoginIn
                },
                {
                    path: "/loginRecord",
                    name: "loginRecord",
                    component: LoginRecord
                }
            ]
        },
        {
            path: "*",
            redirect: "/login"
        },
        {
            path: "/successTips",
            name: "successTips",
            component: SuccessTips
        }
    ]
});
router.beforeEach((to, from, next) => {
    // && !store.state.isLogin
    // console.log("requireAuth>>>>>>>>>>", cookie.getJSON('sysUser'));
    if(to.matched.some(record => record.meta.requireAuth)){
        // 用户信息cookie或者权限被清空要重新登录
        if(!cookie.getJSON('sysUser') || !sessionStorage.getItem('list')){
            // console.log('chongxindengl');
            next({
                path: "/login",
                query: {redirect: to.fullPath}
            });
        };
    }
    next();
});

export default router;
